import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/21 21:58
 */

public class Solution {
    public int HappyNum(int n){
        int sum = 0;
        while(n != 0){
            int t = 0;
            t = n % 10;
            sum += t*t;
            n /= 10;
        }
        return sum;
    }

    public boolean isHappy(int n){
        int slow = n;
        int fast = HappyNum(n);
        while(slow != fast){
            slow = HappyNum(slow);
            fast = HappyNum(HappyNum(fast));
        }
        return slow == 1;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.isHappy(n));
        }
    }
}